package com.lc202309;

/**
 * Description:
 *
 * @Create 2023/8/30 22:48
 * @Version 1.0
 */
public class Solution27 {
    public int removeElement(int[] nums, int val) {
        int length = nums.length;
        int size = length;
        for (int i = 0; i < length; i++) {
            if (nums[length - 1 - i] == val) {
                if(size!=length-i){
                    nums[length - 1 - i] = nums[size - 1];
                }
                size -= 1;
            }
        }
        return size;
    }
}
